﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using POSSystem.BLL;

namespace WebUI.Controls
{
    public partial class EditExpenseCtrl : BaseEditControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!IsPostBack)
            {
                Utilities.LoadDropDownList(ddlPaymentMethod, PaymentMethod.GetAllMethods().DefaultView, PaymentMethod.ColumnNames.Name, PaymentMethod.ColumnNames.ID);
            }
        }

        public string Title
        {
            get { return txtTitle.Text; }
            set { txtTitle.Text = value; }
        }

        public string Description
        {
            get { return txtDesc.Text; }
            set { txtDesc.Text = value; }
        }

        public DateTime SpentDate
        {
            get
            {
                if (txtDate.Text == "")
                    txtDate.Text = DateTime.UtcNow.AddHours(SysVars.TimeZone).ToString(ccDate.Format);
                return DateTime.ParseExact(txtDate.Text, ccDate.Format, null);
            }
            set { txtDate.Text = value.ToString(ccDate.Format); ccDate.SelectedDate = value; }
        }

        public decimal Amount
        {
            get { return decimal.Parse(txtAmount.Text); }
            set { txtAmount.Text = value.ToString(); }
        }

        public string InvoiceNo
        {
            get { return txtInvoiceNo.Text; }
            set { txtInvoiceNo.Text = value; }
        }

        public string Purchaser
        {
            get { return txtPurchaser.Text; }
            set { txtPurchaser.Text = value; }
        }

        public int PaymentMethodID
        {
            get 
            {
                if (ddlPaymentMethod.SelectedIndex == 0)
                    return 0;
                return int.Parse(ddlPaymentMethod.SelectedValue);
            }
            set
            {
                ddlPaymentMethod.SelectedValue = value.ToString();
            }
        }
    }
}